#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main() {
    // 获取当前路径
    char *current_path = getcwd(NULL, 0);
    if (current_path == NULL) {
        perror("Error getting current path");
        return 1;
    }

    // 拼接log.txt文件路径
    char *log_file_path = (char*)malloc(strlen(current_path) + 10);
    if (log_file_path == NULL) {
        perror("Error allocating memory for log file path");
        free(current_path);
        return 1;
    }
    sprintf(log_file_path, "%s/log.txt", current_path);

    // 打开log.txt文件
    int log_file = open(log_file_path, O_RDONLY);
    if (log_file == -1) {
        perror("Error opening log file");
        free(current_path);
        free(log_file_path);
        return 1;
    }

    // 读取log.txt文件内容
    char buffer[1024];
    ssize_t bytes_read;
    while ((bytes_read = read(log_file, buffer, sizeof(buffer))) > 0) {
        buffer[bytes_read] = 0;
        printf("%s", buffer);
    }

    // 关闭log.txt文件
    close(log_file);
    free(current_path);
    free(log_file_path);

    return 0;
}